home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / xludtest.cc < prev    next >
C/C++ Source or Header  |  1989-08-18  |  1KB  |  53 lines

  1. /*
  2.  *    Test program for <T> precision LU decomposition
  3.  *
  4.  *    Copyright (C) 1988, 1989.
  5.  *
  6.  *    Dr. Thomas Keffer
  7.  *    Rogue Wave Associates
  8.  *    P.O. Box 85341
  9.  *    Seattle WA 98145-1341
  10.  *
  11.  *    Permission to use, copy, modify, and distribute this
  12.  *    software and its documentation for any purpose and
  13.  *    without fee is hereby granted, provided that the
  14.  *    above copyright notice appear in all copies and that
  15.  *    both that copyright notice and this permission notice
  16.  *    appear in supporting documentation.
  17.  *    
  18.  *    This software is provided "as is" without any
  19.  *    expressed or implied warranty.
  20.  *
  21.  *
  22.  *    @(#)xludtest.cc    2.1    8/18/89
  23.  */
  24.  
  25. #include "rw/<A>LUDecomp.h"
  26. #include <stream.h>
  27.  
  28. <T> testdata[] = {-3.0, 2.0, 1.0, 8.0, -7.0, 9.0, 5.0, 4.0, -6.0};
  29. <T> testrhs[] = {6.0, 9.0, 1.0};
  30.  
  31. main()
  32. {
  33.   cout << "\n*************** Test LU decomposition ***************\n";
  34.   cout << "\n**** Test inverse ****\n";
  35.  
  36.   <A>GEMatrix testmat(testdata, 3, 3);
  37.  
  38.   cout << NL << "testmat:\n" << testmat <<NL;
  39.  
  40.   cout << NL << "inverse(testmat):\n" << inverse(testmat)<<NL;
  41.  
  42.   <T>Vec rhs(testrhs, 3);
  43.   cout << NL << "rhs:\n" << rhs <<NL;
  44.  
  45.   <T>Vec soln = solve(testmat, rhs);
  46.   cout << NL << "solution:\n" << soln <<NL;
  47.  
  48.   <T>Vec ckrhs = testmat.product(soln);
  49.   cout << NL << "Verification of solution (should match rhs):\n" << ckrhs <<NL;
  50.  
  51.   exit(0);
  52. }
  53.